<section class="content-header">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 代理商首页</a></li>
        <li><a href="#">商户交易</a></li>
        <li class="active">订单管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="jax-box">
        <form id="selectForm" class="form-inline" th:action="@{/agentOrder/list}">
            <div class="form-group">

                <div class="form-group">
                    <label class="control-label">订单编号：</label>
                    <div class="control-inline">
                        <input type="text" name="outTradeNo" class="form-control" />
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">商户编号：</label>
                    <select name="mchId" class="form-control">
                        <option th:each="merch:${merchants}" th:value="${merch.merchMerchantNo}"
                                th:text="${merch.merchName}"></option>
                    </select>
                </div>

                <div class="form-group">
                    <label class="control-label">交易类型：</label>
                    <div class="control-inline">
                        <input type="text" name="serviceType" class="form-control"/>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">交易状态：</label>
                    <select name="tradeStatus" class="form-control">
                        <option value="">==交易状态==</option>
                        <option value="TRADE_FAILE">订单失效</option>
                        <option value="WAIT_BUYER_PAY">等待支付</option>
                        <option value="TRADE_CLOSED">订单关闭</option>
                        <option value="TRADE_SUCCESS">交易成功</option>
                        <option value="TRADE_FINISHED">交易完成</option>
                    </select>
                </div>

                <div class="form-group">
                    <label class="control-label">交易时间：</label>
                    <input type="text" class="form-control" name="createTimeString" id="startDate"
                           onclick="WdatePicker({isShowClear:true,dateFmt:'yyyy-MM-dd',onpicked:function(){endDate.click();}})" />
                    --
                    <input type="text" class="form-control" name="endTimeString" id="endDate"
                           onclick="WdatePicker({isShowClear:true,dateFmt:'yyyy-MM-dd'})" />
                </div>

                <shiro:hasPermission name="agentOrder:list">
                    <div class="btn-group btn-group-sm" style="text-align:left;">
                        <button type="button" id="btn_query" class="btn btn-info">查询</button>
                        <button type="reset" id="btn_reset" class="btn btn-warning">重置</button>
                    </div>
                </shiro:hasPermission>
            </div>
        </form>
    </div>
    <div class="jax-box jax-box-table">

        <div id="toolbar" class="toolbar btn-group">
            <!--<shiro:hasPermission name="agent:add">-->
                <!--<button id="btn_add" type="button" class="btn btn-primary" data-toggle="modal" data-target="#agentModal">-->
                    <!--<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>导出订单-->
                <!--</button>-->
            <!--</shiro:hasPermission>-->

        </div>

        <div class="wrapper-content">
            <div class="ibox-content animated fadeInRight">
                <div class="jqGrid_wrapper">
                    <table id="table_list"></table>
                    <div id="pager_list"></div>
                </div>
            </div>
        </div>

    </div>
</section>

<script type="text/javascript">

    $(document).ready(function () {
        var dataGrid = new DataGrid({
            dataGrid: $('#table_list'),
            searchForm: $('#selectForm'),
            dataGridPage: $('#pager_list'),

            rownumbers: true,
            rownumWidth: 60,
            colModel: [
                {
                    header: '代理商名称',
                    name: 'agentName',
                    index: 'agentName',
                    editable: false,
                    width: 60,
                    sortable: false,
                    search: false
                },
                {
                    header: '商户流水号',
                    name: 'outTradeNo',
                    index: 'outTradeNo',
                    width: 60,
                    align: 'left',
                    sortable: false
                },
                {
                    header: '交易金额',
                    name: 'totalFee',
                    index: 'totalFee',
                    sortable: false, formatter: moneyFormat,
                    width: 35
                },
                {
                    header: '商户金额',
                    name: 'profit',
                    index: 'profit',
                    sortable: false, formatter: moneyFormat,
                    width: 35
                },
                {
                    header: '交易状态',
                    name: 'tradeStatus',
                    index: 'tradeStatus',
                    editable: true,
                    width: 40,
                    sortable: false,
                    formatter: function (value) {
                        switch (value) {
                            case 'TRADE_FAILE':
                                return '订单失效';
                            case 'WAIT_BUYER_PAY':
                                return '等待支付';
                            case 'TRADE_CLOSED':
                                return '订单关闭';
                            case 'TRADE_SUCCESS':
                                return '交易成功';
                            case 'TRADE_FINISHED':
                                return '交易完成';
                            default:
                                return "订单失效";
                        }
                    }
                },
                {
                    header: '交易类型',
                    name: 'serviceType',
                    index: 'serviceType',
                    editable: true,
                    width: 60,
                    sortable: false
                },
                {
                    header: '上游商户号',
                    name: 'srcMchId',
                    index: 'srcMchId',
                    width: 60,
                    align: 'left',
                    sortable: false
                },
                {
                    header: '上游订单号',
                    name: 'srcOrderNo',
                    index: 'srcOrderNo',
                    width: 60,
                    align: 'left',
                    sortable: false
                },
                {
                    header: '上游返回信息',
                    name: 'srcReason',
                    index: 'srcReason',
                    editable: true,
                    width: 40,
                    sortable: false
                },
                {
                    header: '创建时间',
                    name: 'createTime',
                    index: 'createTime',
                    editable: false,
                    sortable: false,
                    width: 60
                },
                {
                    header: '支付时间',
                    name: 'payTime',
                    index: 'payTime',
                    editable: true,
                    sortable: false,
                    width: 60
                }
            ],
            footerrow: true, //分页上添加一行，用于显示统计信息
            userDataOnFooter: true,
            altRows: true
        });

        $("#btn_query").click(function () {
            $("#table_list").jqGrid('setGridParam', {
                datatype: 'json',
                postData: {
                    outTradeNo: $('input[name=outTradeNo]').val(),
                    mchId: $('select[name=mchId]').val(),
                    tradeStatus: $('select[name=tradeStatus]').val(),
                    serviceType: $('input[name=serviceType]').val(),
                    createTimeString: $('input[name=createTimeString]').val(),
                    endTimeString: $('input[name=endTimeString]').val()
                }, // 发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });
    });

    function moneyFormat(cellValue) {
        if (cellValue == null || cellValue == '') {
            cellValue = 0;
        }
        cellValue = cellValue.toFixed(2);
        var total_p = "￥" + cellValue;

        return total_p;
    };
</script>